using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {
	// Update is called once per frame
    GameObject target;

	void LateUpdate () {
        if (!target)
        {
            target = GameObject.FindWithTag("Player");
        }
		if( !target )
			return;

		Vector3 targetPos;
		targetPos =  ( target.transform.position ) - target.transform.forward * 7.5f;
		targetPos.y = 7.5f;
		transform.position = Vector3.Slerp( transform.position, targetPos, Time.deltaTime * 20.0f );

		Vector3 toward;
		Quaternion targetRot;
		toward	= ( target.transform.position + target.transform.rotation * Vector3.forward * 5.0f ) - transform.position;
		targetRot = Quaternion.LookRotation( toward, Vector3.up );

		Quaternion currentRot = Quaternion.Slerp( transform.rotation, targetRot, Time.deltaTime * 25.0f );
		
		transform.rotation = currentRot;
	}
}
